<template>
	<view class="page red">
		<!-- header -->
		<cu-custom bgColor="#f24b4f" :leftflag="{flag: true, left: 0}" :isBack="false" :contentStyle="{
			color: '#fff',
			fontSize: '30px',
			textAlign: 'left',
			fontWeight: 600,
			textIndent: '1em',
			right: 'auto'
		}">
			<block slot="content">积分榜</block>
		</cu-custom>

		<!-- 背景图 -->
		<view class="banner">
			<!-- <view class="banner-image" :style="{background: `url(${'/static/integral/red_banner.png'}) no-repeat top`}"></view> -->
			<image class="banner-image" src="/static/integral/red_banner.png"></image>
		</view>
		<!-- title -->
		<!-- <view class="color-white just-start">
			<text @tap="showModal" data-type="title">
				<text>{{titleName.name}}</text>
				<text class="lg color-white text-gray cuIcon-triangledownfill"></text>
			</text>
		</view> -->
		<!-- 选择Date -->
		<scroll-view scroll-x class="nav text-left">
			<view class="cu-item" style="padding:0 10rpx;" :class="index==TabCur?'text-white cur':''" v-for="(item,index) in aDate"
			 :key="index" @tap="tabSelect" :data-id="index">
				{{item}}
			</view>
		</scroll-view>

		<!-- town -->
		<view class="color-white  just-start mt30">
			<text class="bg-round" @tap="showModal" data-type="town">
				<text>{{townName.name}}</text>
				<text class="lg color-white text-gray cuIcon-triangledownfill"></text>
			</text>
		</view>
		<!-- 单选模态框 -->
		<view class="cu-modal" :class="modalName?'show':''" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<radio-group class="block" @change="RadioChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item, index) in aRadio" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="flex-sub">{{item.name}}</view>
								<radio class="round" :class="item.checked" :checked="item.checked" :value="item.value"></radio>
							</label>
						</view>
					</view>
				</radio-group>
			</view>
		</view>

		<!-- 前3list -->
		<i-list :first="first" :second="second" :third="third" class="w100"></i-list>
		<!-- 剩余list -->
		<view class="cu-list menu-avatar w100">

			<view class="cu-item sm-border" v-for="(item, index) in other" :key="index">
				<view class="item-rank">
					{{4+index}}
				</view>
				<view :class="item.userInfo.avatarUrl ? '':'cuIcon-profile'" class="cu-avatar lg round lg margin-left" :style="item.userInfo.avatarUrl && `background-image: url(${item.userInfo.avatarUrl});left:80rpx;`">
				</view>
				<view class="content content-left" style="left: 185rpx;">

					<view class="text-grey item-ml color-bla">
						{{item.name ? item.name : item.userInfo.nickName }}
					</view>
					<view class="text-gray text-sm flex item-wrap">
						<view class="item-ml">活动数量：{{item.aJoin.length || '0' }}</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-xs color-bla">
						<text class="list-large">{{item.integral || '0' }}</text>
						<!-- <text class="list-per">.23</text> -->
					</view>
				</view>
			</view>
		</view>


		<!-- 分享 -->
		<button class="share-btn" open-type="share">
			<!-- <view class="share-img radius bg-img" style="background-image:url(../../static/share.png);">
				<view>根据背景图而改变的阴影</view> 
			</view> -->
			<text class="bg-img lg text-green cuIcon-share"></text>
		</button>


	</view>
</template>

<script>
	const {
		request,
	} = require('@/utils/t-request.js');
	import IList from "@/components/integral/i-list.vue";
	export default {
		components: {
			'i-list': IList
		},
		data() {
			return {
				TabCur: 0,
				aDate: ['积分总计'
				// , '活动数量',
				],
				modalName: false,
				radioType: '',
				title: [{
					value: 0,
					name: '不用title',
					checked: true,
				}, ],
				town: [{
					value: 0,
					name: '双桥村',
					checked: true,
				}, ],
				// 数据
				first: {},
				second: {},
				third: {},
				other: []
			}
		},
		computed: {
			aRadio() {
				return this.radioType ? this[this.radioType] : [];
			},
			titleName() {
				return this.title.filter(item => item.checked)[0]
			},
			townName() {
				return this.town.filter(item => item.checked)[0]
			},
		},
		methods: {
			/**
			 * 长期 月 周 日
			 * @param {Object} e
			 */
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				// TODO: 更新数据
			},
			/***************** 模态-单选-end ***************/
			showModal(e) {
				this.radioType = e.currentTarget.dataset.type;
				this.modalName = true;
			},
			hideModal() {
				this.modalName = false;
				this.radioType = '';
			},
			RadioChange(e) {
				this[this.radioType].forEach((item, index) => {
					if (item.value == e.detail.value) {
						item.checked = true;
					} else {
						item.checked = false;
					}
				})
				console.log(this[this.radioType])
				this.radioType = '';
				this.hideModal();
			},
			/***************** 模态-单选-end ***************/
		},
		onShow() {
			request({
				url: "/users/user-many",
				method: 'POST',
			}).then(res => {
				this.first = res.data.first;
				this.second = res.data.second;
				this.third = res.data.third;
				this.other = res.data.other;
			});
		}
	}
</script>

<style>
	.share-btn {
		position: fixed;
		right: 20rpx;
		bottom: 50rpx;
		padding: 0;
		border-radius: 50%;
		background-color: rgba(0, 0, 0, 0.6);
		width: 80rpx;
		height: 80rpx;
		font-size: 32rpx;
	}

	.share-img {
		width: 100rpx;
		height: 100rpx;
	}

	.red {
		background-color: #f24b4f;
	}


	.page {
		display: flex;
		flex-direction: column;
		align-items: center;
		min-height: 100%;
		width: 100%;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
	}

	.banner {
		position: relative;
		color: #fffefe;
		display: flex;
		flex-direction: column;
		width: 90%;
		margin-bottom: 40rpx;
		z-index: -10;
	}

	.banner-image {
		height: 412rpx;
		width: 378rpx;
		position: absolute;
		top: 10rpx;
		right: 0rpx;
	}

	.color-white {
		color: #FFFFFF;
		font-size: 36rpx;
	}

	.bg-round {
		background-color: rgba(0, 0, 0, 0.3);
		font-size: 28rpx;
		padding: 10rpx;
		border-radius: 10rpx;
	}

	.just-start {
		width: 100%;
		margin-left: 50rpx;
	}

	.mt30 {
		margin-top: 30rpx;
	}

	/* 组件宽度丢失 */
	.w100 {
		width: 100%;
	}

	.item-wrap {
		flex-wrap: wrap;
	}

	.item-ml {
		margin-left: 30rpx;
	}

	.color-bla {
		color: #000000;
		font-size: 28rpx;
		font-family: 'PingFang-SC-Bold';
		font-weight: bold;
	}

	.list-large {
		font-size: 30rpx;
		line-height: 26rpx;
	}

	.list-per {
		margin-left: 8rpx;
		font-size: 24rpx;
	}

	.item-rank {
		color: #999;
		font-size: 60rpx;
		font-family: 'PingFang-SC-Medium';
		font-weight: 500;
		min-width: 60rpx;
		position: absolute;
		left: 30rpx;
	}
</style>
